package hotel.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetExtractor;
import org.springframework.stereotype.Repository;

import hotel.dao.UsedRoomDao;
import hotel.pojo.ManagerDto;
import hotel.pojo.RoomDto;

@Repository
public class UsedRoomDaoImpl implements UsedRoomDao{
	@Resource(name="mysqlJdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	
	public List<RoomDto> roomUse(String Rstatus) {
		String sql = "SELECT * FROM room WHERE Rstate = ?";
		
		ResultSetExtractor<List<RoomDto>> lists = new ResultSetExtractor<List<RoomDto>>() {
			public List<RoomDto> extractData(ResultSet rs) throws SQLException, DataAccessException{
				List<RoomDto> lists = new ArrayList<RoomDto>();
				while(rs.next()) {
					String num = rs.getString("Rnum");
					String level = rs.getString("Rlevel");
					String type = rs.getString("Rtype");
					String price = rs.getString("Rprice");
					String state = rs.getString("Rstate");
					RoomDto roomDto = new RoomDto(num,level,type,price,state);
					lists.add(roomDto);
				}
				return lists;
			}
		};	
		return jdbcTemplate.query(sql,new Object[] {Rstatus},lists);
		
	}

}
